//
//  CLMovieViewModel.m
//  Charles
//
//  Created by Leo on 2017/6/8.
//  Copyright © 2017年 charles. All rights reserved.
//

#import "CLMovieViewModel.h"
#import "CLMvvmViewController.h"
#import "CLMovieModel.h"
#import "NetworkService.h"
@implementation CLMovieViewModel

- (void)getMovieData{
    [NetworkService requestWithURL:@"/v2/movie/coming_soon" params:nil success:^(id result) {
        NSLog(@"%@",result);
        
        NSArray *subjects = result[@"subjects"];
        NSMutableArray *modelArr = [NSMutableArray arrayWithCapacity:subjects.count];
        for (NSDictionary *subject in subjects) {
            CLMovieModel *model = [[CLMovieModel alloc] init];
            model.movieName = subject[@"title"];
            model.year = subject[@"year"];
            NSString *urlStr = subject[@"images"][@"medium"];
            model.imageUrl = [NSURL URLWithString:urlStr];
            model.detailUrl = subject[@"alt"];
            [modelArr addObject:model];
        }
        _returnBlock(modelArr);
        
    } failure:^(NSError *error) {
        NSLog(@"%@",error);
        _errorBlock(error);
    }];
}

- (void)movieDetailWithPublicModel: (CLMovieModel *)movieModel WithViewController: (UIViewController *)superController{
    NSLog(@"Charles Mvvm!!");
}
@end
